package lab03.test03;

import java.io.*;

public class Test03 {
    public static void main(String[] args) throws IOException {
              File f=new File("D:\\test.txt");

        if (!f.exists()) {//判断test.txt是否存在
            try {
                f.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        //将文本放入字节数组
        byte [] arr="beijing 欢迎你".getBytes();
        FileOutputStream out= null;
        try {
            out = new FileOutputStream(f);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        try {
            out.write(arr);
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        FileReader in=new FileReader(f);

        int i=0;

        while((i=in.read())!=-1){

            System.out.print((char)i);
        }

        System.out.println();


        FileWriter writer=new FileWriter("D://test.txt",true);
        writer.write("我的学号是：1606101026");
        writer.close();


        FileReader fileReader=new FileReader(f);

        int j=0;
        while((j=fileReader.read())!=-1){

            System.out.print((char)j);
        }

    }
}
